package Textbookmanagement;

import java.util.regex.*;

public class Statistics {
    Sell sell = new Sell();
    public double sum;

    public void show() {
        System.out.println("1.每日统计      2.按库位号统计    ");
        System.out.println("3.销售统计      0.退出");
        System.out.println("请输入功能：");
    }

    public void Dailystatistics() {//每日统计
        //获取当前日期
        System.out.println("今日预定书籍：");
        Pattern p = Pattern.compile("[a-zA-Z\\u4e00-\\u9fa5]+");
        Matcher m = p.matcher(Order.nameprice);
        while (m.find()) {
            System.out.print("《" + m.group() + "》" + '\t');
        }
        System.out.println(" ");
        System.out.println("今日出售书籍：");
        System.out.println("《" + Sell.name + "》");
    }

    public void librarylocation() {//库位号统计

        System.out.println(Order.num + "号库中的书籍有：");
        sell.delete();
    }

    public void SaleSstatistics() {//销售统计
        String str1 = Order.nameprice;
        String regex = "[\\s\\d\\p{Punct}]+";
        String[] dihitword = str1.split(regex);
        System.out.println("今日预定的书籍有：");
        for (String s : dihitword) {
            System.out.println("《" + s + "》");
        }
        if (Sell.name != null) {
            String str2 = Sell.name;
            String[] book = str2.split(regex);
            System.out.println("今日共出售" + book.length + " 本书:");
            for (String s : book) {
                System.out.println("《" + s + "》");
            }
        } else {
            System.out.println("今天没有卖出书。");
        }
        String str3 = Order.nameprice;
        String[] money = str3.split("\\D+");
        int sum = 0;
        for (String string : money) {
            if (!"".equals(string)) {
                sum += Integer.parseInt(string);
            }
        }

        System.out.println("预定书籍支出" + sum + "元");

        System.out.println("出售书籍收入" + Sell.price + "元");
        if (sum > Sell.price) {
            System.out.println("今日盈利" + (sum - Sell.price));
        } else
            System.out.println("今日盈利：" + (Sell.price - sum));
    }

}